<template>
  <div class="subtmpl">
    <div class="left" @click="substrict">-</div>
    <div class="middle"> {{ count }}</div>
    <div class="right" @click="add">+</div>
  </div>
</template>

<script>

export default {
 		data(){
 			return{
 				count:1
 			
 			}
     }
    //  ,props:['initcount,'goodsid']
    //  ,
    //  created(){
    //    thid.count = this.initcount>1?this.initcount:1;
    //  }
     ,methods:{
       //这是加1
              add(){
                     this.count++;
                     this.notiflycount();
                },
        //这是减1
                substrict(){
                  //最后等于1
                  if(this.count<=1){
                     this.count =1;
                     return;
                     }
                    this.count--;
                    this.notiflycount();
                }
                // 最新的count传入父组件
                ,notiflycount(){
                        let key = "count";
                        this.$emit(key,this.count);//执行后悔触发
                }

		 }
 		
}
</script>

<style lang="scss" scoped>
.subtmpl div{
    display: inline-block;
    padding: 5px;
    border: 1px solid #eee;
}
.left,.right{
  height: 25px;
  width: 30px;
  line-height: 15px;
  text-align: center;

}
.middle{
  height: 25px;
  line-height: 15px;
  width: 40px;
  text-align: center;
}
   
</style>
